package com.stnet.web.enterprice.base;

import java.io.File;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.modules.commons.PageAction;
import com.opensymphony.xwork2.ActionContext;
import com.stnet.bases.Constants;
import com.stnet.entity.Standby;

public class StandbyAction extends PageAction {

	private static final long serialVersionUID = 1L;
	private List<Standby> standbyList;
	private Standby standby;
	
	public StandbyAction(){
	}
	
	public String execute()throws Exception {
		super.pager = standbyManagerDao.getStandbyList(pageSize, pageNo, "-1");
		standbyList = super.pager.getResultList();
		return Constants.SUCCESS_KEY;
	}
	
	public String query() throws Exception {
		super.pager = standbyManagerDao.getStandbyList(pageSize, pageNo, "-1");
		List resultList = super.pager.getResultList();
		setStandbyList(resultList);
		pageSize=super.pager.getPageSize();
		pageNo=super.pager.getPageNo();
		return Constants.SUCCESS_KEY;
	}
	
	public String addPage() throws Exception {
		return "addPage";
	}
	
	public String add() throws Exception {
		standbyManagerDao.addStandby(standby);
		return this.execute();
	}
	
	public String editStandby() throws Exception {
		ActionContext context=ActionContext.getContext();   
		HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);  
		Long id = Long.valueOf(request.getParameter("id"));
		standby = standbyManagerDao.getStandbyById(id);
		return "editStandby";
	}
	
	public String update() throws Exception {
		Standby newStandby = standbyManagerDao.getStandbyById(standby.getId());
		newStandby.setStandby1(standby.getStandby1());
		newStandby.setStandby2(standby.getStandby2());
		newStandby.setStandby3(standby.getStandby3());
		newStandby.setStandby4(standby.getStandby4());
		newStandby.setStandby5(standby.getStandby5());
		newStandby.setStandby6(standby.getStandby6());
		newStandby.setStandby7(standby.getStandby7());
		newStandby.setStandby8(standby.getStandby8());
		newStandby.setStandby9(standby.getStandby9());
		standbyManagerDao.update(newStandby);
		return this.execute();
	}
	
	public String delete() throws Exception {
		ActionContext context=ActionContext.getContext();   
		HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);  
		Long id = Long.valueOf(request.getParameter("id"));
		standbyManagerDao.delete(id);
		return this.execute();
	}
	

	public List<Standby> getStandbyList() {
		return standbyList;
	}

	public void setStandbyList(List<Standby> standbyList) {
		this.standbyList = standbyList;
	}

	public Standby getStandby() {
		return standby;
	}

	public void setStandby(Standby standby) {
		this.standby = standby;
	}
	
}
